package com.mijie.homi.dao.topic;

import java.util.List;
import java.util.HashMap;

import org.springframework.stereotype.Repository;

import com.mijie.core.IBatisDao;
import com.mijie.homi.domain.topic.TopicOpinion;

@Repository
public class TopicOpinionDao extends IBatisDao {

	public long postTopicOpinion(TopicOpinion opinion){
		 this.insert("postTopicOpinion", opinion);
		 return opinion.getId();
	}
	
	public int likeOpinion(long id){
		return this.update("likeOpinion",id);
	}
	
	public TopicOpinion getTopicOpinionById(long id){
		return this.selectOne("getTopicOpinionById", id);
	}
	
	public List<TopicOpinion> listTopicOpinion(int topicId,long idx,int limit){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("topicId", topicId);
		parameter.put("idx", idx);
		parameter.put("limit", limit);
		return this.selectList("listTopicOpinion", parameter);
	}
	
	public int deleteOpinion(int reviewer,long id){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("reviewer", reviewer);
		parameter.put("id", id);
		return this.delete("deleteOpinion", parameter);
	}
	
	public Integer countCommentByTopicId(int topicId){
		return this.selectInteger("countCommentByTopicId", topicId);
	}
	
	public int increNumOfReview(long id) {
		return this.update("increOpinionNumOfReview", id);
	}

	public int decreNumOfReview(long id) {
		return this.update("decreOpinionNumOfReview", id);
	}
}
